/*

Oolite
Copyright © 2004-2008 Giles C Williams and contributors

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/


this.name			= "oreProcessorSplinter";
this.author			= "Eric Walch";
this.copyright		= "Share alike";
this.version		= "1.1";


this.shipWasScooped = function (scooper)
{
    var message = this.ship.scriptInfo.message
    var cargotype = this.ship.scriptInfo.cargotype
    var quantity = this.ship.scriptInfo.quantity

    // Scooping already means there was 1 ton of empty space. So no check here.
	if (scooper.isPlayer)
	{
		if(quantity < 0) quantity= Math.ceil(Math.random()*(-quantity)); // only negative values are randomised.
		if(quantity > 1) {message = message.replace("gr ", "grs "); message = message.replace("kilogram ", "kilograms ")};

		if(scooper.hasEquipment("EQ_ORE_PROCESSOR") && scooper.energy > 128)
		{
            worldScripts.oreProcessor.addOre(message.replace("@1", quantity), cargotype, quantity)
		}
		else
		{
            player.consoleMessage("No extraction!! 1 ton ore")
            scooper.awardCargo("Minerals", 1)
		}

	}
	// do something with NPC once possible
}
